home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-07-24 | 6.0 KB | 201 lines | [TEXT/CWIE] |
- // ===========================================================================
- // Exhibit.cp - show how the UGetMultipleFiles class works
- // ===========================================================================
- //
- // This file contains the starter code for a PowerPlant application
-
- #include "Exhibit.h"
-
- #include <LGrowZone.h>
- #include <LWindow.h>
- #include <PP_Messages.h>
- #include <PP_Resources.h>
- #include <PPobClasses.h>
- #include <UDrawingState.h>
- #include <UMemoryMgr.h>
- #include <URegistrar.h>
- #include <LEditField.h>
-
-
- // ===========================================================================
- // • Main Program
- // ===========================================================================
-
- void main(void)
- {
- // Set Debugging options
- SetDebugThrow_(debugAction_Alert);
- SetDebugSignal_(debugAction_Alert);
-
- InitializeHeap(3); // Initialize Memory Manager
- // Parameter is number of Master Pointer
- // blocks to allocate
-
- // Initialize standard Toolbox managers
- UQDGlobals::InitializeToolbox(&qd);
-
- new LGrowZone(20000); // Install a GrowZone function to catch
- // low memory situations.
-
- Exhibit theApp; // replace this with your App type
- theApp.Run();
- }
-
-
- // ---------------------------------------------------------------------------
- // • Exhibit // replace this with your App type
- // ---------------------------------------------------------------------------
- // Constructor
-
- Exhibit::Exhibit()
- {
- }
-
-
- // ---------------------------------------------------------------------------
- // • ~Exhibit // replace this with your App type
- // ---------------------------------------------------------------------------
- // Destructor
- //
-
- Exhibit::~Exhibit()
- {
- }
-
- // ---------------------------------------------------------------------------
- // • StartUp
- // ---------------------------------------------------------------------------
- // This function lets you do something when the application starts up
- // without a document. For example, you could issue your own new command.
-
- void
- Exhibit::StartUp()
- {
- ObeyCommand(cmd_New, nil); // Do the add files command
- }
-
- // ---------------------------------------------------------------------------
- // • ObeyCommand
- // ---------------------------------------------------------------------------
- // Respond to commands
- #include "UGetMultipleFiles.h"
- Boolean
- Exhibit::ObeyCommand(
- CommandT inCommand,
- void *ioParam)
- {
- Boolean cmdHandled = true;
-
- switch (inCommand) {
-
- // Deal with command messages (defined in PP_Messages.h).
- // Any that you don't handle will be passed to LApplication
-
- case cmd_New:
- {
- // this time through chooses files that will be excluded from the next time
- UGetMultipleFiles *selectBadFilesThing = nil;
- LArray *suppressedFSpecs = nil;
- selectBadFilesThing = new UGetMultipleFiles("\pChoose Files to Exclude",
- (short) -1, // number of types to show (-1 means all)
- (unsigned long *) nil, // the list of types
- nil, // the list of files to exclude
- true, // allow MAE to convert files?
- true, // show folders?
- false); // add folders?
-
- if ((selectBadFilesThing->GetSFReply()).sfGood) {
- suppressedFSpecs = selectBadFilesThing->GetFSSpecs();
- } else {
- // user chose cancel, or there were no files selected
- suppressedFSpecs = nil;
- }
-
- // copy selected files to a new LArray. We have to do this because all the
- // data members of UGetMultipleFiles are static, so we will be overwriting
- // the old ones if we don't delete selectBadFilesThing before creating
- // theMultFilesThing
- LArray suppressedFSSpecsCopy(sizeof(FSSpec)); // create the FSSpec array
- if (suppressedFSpecs != nil) {
- FSSpec *thisSpecP;
- for (short i = 1; i <= suppressedFSpecs->GetCount(); i++) {
- thisSpecP = (FSSpec *)suppressedFSpecs->GetItemPtr(i);
- suppressedFSSpecsCopy.InsertItemsAt(1, suppressedFSSpecsCopy.index_Last, thisSpecP);
- }
- suppressedFSpecs->RemoveItemsAt(suppressedFSpecs->GetCount(), 1);
- }
- delete selectBadFilesThing;
-
-
- // now we demonstrate selecting multiple files and folders, and filtering out certain ones
- // since we don't want MacEasyOpen to deal with file conversion, we'll specify a fourth
- // parameter of false for the sAllowConversion to avoid trouble with MacEasyOpen
- SFTypeList typeList;
- FSSpec oneFSSpec;
- UGetMultipleFiles *theMultFilesThing;
- LArray *theFSpecs;
- short i;
-
- typeList[0] = 'TEXT';
- typeList[1] = 'inGT';
-
- theMultFilesThing = new UGetMultipleFiles("\pChoose files for processing:",
- 2, // number of types to show (-1 means all)
- typeList, // the list of types
- &suppressedFSSpecsCopy, // the list of files to exclude
- false, // allow MAE to convert files?
- true, // show folders?
- true); // add folders?
-
- if ((theMultFilesThing->GetSFReply()).sfGood) {
- theFSpecs = theMultFilesThing->GetFSSpecs();
- for (i = 1; i <= theFSpecs->GetCount(); i++) {
- theFSpecs->FetchItemAt(i, &oneFSSpec);
- ParamText(oneFSSpec.name, "\p", "\p", "\p");
- Alert(129, nil);
- }
- } else {
- // user chose cancel, or there were no files selected
- }
- delete theMultFilesThing;
- }
- break;
- default:
- cmdHandled = LApplication::ObeyCommand(inCommand, ioParam);
- break;
- }
-
- return cmdHandled;
- }
-
- // ---------------------------------------------------------------------------
- // • FindCommandStatus
- // ---------------------------------------------------------------------------
- // This function enables menu commands.
- //
-
- void
- Exhibit::FindCommandStatus(
- CommandT inCommand,
- Boolean &outEnabled,
- Boolean &outUsesMark,
- Char16 &outMark,
- Str255 outName)
- {
-
- switch (inCommand) {
-
- // Return menu item status according to command messages.
- // Any that you don't handle will be passed to LApplication
-
- case cmd_New: // EXAMPLE
- outEnabled = true; // enable the New command
- break;
-
- default:
- LApplication::FindCommandStatus(inCommand, outEnabled,
- outUsesMark, outMark, outName);
- break;
- }
- }
-